//
// Created by Admin on 2021/9/20.
//

#include "entry.h"

typedef struct {
    int excellent,good,medium,qualified,disqualified;
}SubjectLevel,*pSubjectLevel;

void statistic_(pStudent students, int student_count, int subject_count){
    pSubjectLevel subjectsLevel = calloc(subject_count,sizeof(SubjectLevel));
    for(int i=0;i<student_count;i++){
        for(int j=0;j<subject_count;j++){
            int score = students[i].subjects[j].score;
            if(90 < score && score <= 100){
                ++subjectsLevel[j].excellent;
            }else if(80<score&&score<=90){
                ++subjectsLevel[j].good;
            } else if(70<score&&score<=80){
                ++subjectsLevel[j].medium;
            }else if(60<=score&&score<=70){
                ++subjectsLevel[j].qualified;
            }else if(score<60){
                ++subjectsLevel[j].disqualified;
            }
        }
    }
    printf("统计结果：\n");
    for(int i=0;i<subject_count;i++){
        printf("\t课程%d: \n\t\t优秀人数%d,占比%f%%;\n\t\t良好人数%d,占比%f%%; \n\t\t中等人数%d,占比%f%%; \n\t\t及格人数%d,占比%f%%; \n\t\t不及格人数%d,占比%f%%\n",i,
                subjectsLevel[i].excellent,100.0* subjectsLevel[i].excellent/student_count,
                subjectsLevel[i].good,100.0* subjectsLevel[i].good/student_count,
                subjectsLevel[i].medium,100.0* subjectsLevel[i].medium/student_count,
                subjectsLevel[i].qualified,100.0* subjectsLevel[i].qualified/student_count,
                subjectsLevel[i].disqualified,100.0* subjectsLevel[i].disqualified/student_count);
    }

    free(subjectsLevel);
}